<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="false">
			<block slot="content">个人中心</block>
		</cu-custom>
		<view class="bg-blue padding flex justify-between align-center">
			<view class="flex">
				<view class="cu-avatar round xl" :style="'background-image:url(' + userInfo.avatar + ')'">
				</view>
				<view class="padding-lr">
					<view class="text-xl">
						{{userInfo.nikeName}}
					</view>
					<view>
						{{userInfo.phone}}
					</view>
				</view>

			</view>
			<view class="text-xxl">
				<text class="cuIcon-settings text-white"></text>
			</view>

		</view>
		<view class="cu-list menu sm-border margin-sm">
			<view class="cu-item arrow">
				<view class="content">
					<text class="cuIcon-settings text-grey"></text>
					<text class="text-grey">账号安全</text>
				</view>
			</view>
			<view class="cu-item arrow">
				<view class="content">
					<text class="cuIcon-peoplelist text-grey"></text>
					<text class="text-grey">关于我们</text>
				</view>
			</view>
		</view>
		<view class="padding">
			<button class="cu-btn shadow-blur block margin-tb-sm bottom-btn bg-blue" @tap="doLogout">安全退出</button>
		</view>
		<view class="text-grey text-sm text-center margin-sm">环兴商城 版本所有（{{versionNumber}}）</view>
	</view>
</template>

<script>
	import {
		getUserInfo,
		logout
	} from '@/api/login.js'
	export default {
		data() {
			return {
				versionNumber: '1.0.0',
				userInfo: {}
			}
		},
		onLoad() {
			this.getInfo();
		},
		methods: {
			getInfo() {
				getUserInfo().then(res => {
					this.userInfo = res.data
					uni.setStorageSync('user_info', userInfo);
				})
			},
			doLogout() {
				logout().then(res => {
					uni.reLaunch({
						url: '/pages/login/index'
					})
					uni.removeStorageSync('access_token');
					uni.removeStorageSync('expires_in');
				})
			}
		}
	}
</script>

<style>
</style>
